package com.geek.config.dynamic;

import javax.management.*;
import java.io.IOException;
import java.lang.management.ManagementFactory;

/**
 * @Author: ysq
 * @Date: 2021/7/20
 * @Description:  动态MBean注册 demo   cmd -> jconsole 建立连接
 */
public class Client {
  public static void main(String[] args) throws MalformedObjectNameException, InstanceAlreadyExistsException
          , MBeanRegistrationException, NotCompliantMBeanException, IOException {

    DynamicUser dynamicUser = new DynamicUser();
    String packageName = dynamicUser.getClass().getPackage().getName();
    String simpleName = dynamicUser.getClass().getSimpleName();

    ObjectName objectName = new ObjectName(packageName + ":type=" + simpleName);
    ManagementFactory.getPlatformMBeanServer()
            .registerMBean(dynamicUser, objectName);

    System.out.println("Press any key to exit");
    System.in.read();




  }
}
